package gerenciaDados.cln.cgt.PI.descricaoeRepresentacao;

import java.awt.Color;
import java.awt.image.BufferedImage;

public class Cores {
	private BufferedImage img;
	private BufferedImage imgbw;
	public Cores(BufferedImage img,BufferedImage imgbw)
	{
		this.img = img;
		this.imgbw = imgbw;
	}
	
	public double [] extracao()
	{
		int l = img.getWidth();
		int a = img.getHeight();
		int branco = Color.WHITE.getRGB();
		int [] px = img.getRGB(0, 0, l, a, null, 0, l);		
		int [] mask = imgbw.getRGB(0, 0, l, a, null, 0, l);
		
		double rsum=0.0;
		double gsum=0.0;
		double bsum=0.0;		
		Color c;
		
		for(int i=0; i<a; i++)
		{
			for(int j=0; j<l; j++)
			{
				if(mask[i*l + j] ==  branco)
				{
					c = new Color(px[i*l + j]);					
					rsum += (double)c.getRed()/(double)255;
					gsum += (double)c.getGreen()/(double)255;
					bsum += (double)c.getBlue()/(double)255;
				}
			}
		}
		
		double soma = rsum + gsum + bsum;
		rsum = rsum / soma;
		gsum = gsum / soma;
		bsum = bsum / soma;
		double [] RGB = {rsum, gsum, bsum};		
		return RGB;
	}
}

